package ranks.tasks.readable;

import java.io.IOException;

import mapred.example.base.TextMapper;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

import ranks.Customize;
import ranks.base.Data;

public class Readable_Mapper extends TextMapper {

    private static long N;

    private static Data z;

    @Override
    public void map(Text key, Text value, OutputCollector<Text, Text> output,
            Reporter reporter) throws IOException {
        String text = value.toString();
        Data rank = new Data(text.substring(0, text.indexOf("\t")));
        rank.add(z);

        output.collect(key, new Text(Customize.readable(rank, N)));
    }

    @Override
    public void setUp() {
        N = Long.parseLong(this.getJobConfConfig("WebSize"));
        z = new Data(this.getJobConfConfig("Z"));
    }

}
